﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Theme_3_AddComment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string rid = Request.QueryString["ResourceID"].ToString();
            string playtime = Request.QueryString["playtime"].ToString();
            string userid = Request.QueryString["UserID"].ToString();
            ViewState["UserID"] = userid;
            ViewState["ResourceID"] = rid;
            ViewState["PlayTime"] = playtime.ToString();
            ViewState["RealName"] = "";
            ViewState["UserName"] = "";
            if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] != null)
            {
                PowerCreator.LMS.Web.User.LoginEntity login = (PowerCreator.LMS.Web.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
                ViewState["RealName"] = login.AccountInfo.RealName;
                ViewState["UserName"] = login.UserName;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        PowerCreator.LMS.Web.Comment.Comment commentManager = new PowerCreator.LMS.Web.Comment.Comment();
        PowerCreator.LMS.Comment.Entity.VOSysPLCommentInfo cinfo = new PowerCreator.LMS.Comment.Entity.VOSysPLCommentInfo();
        cinfo.CommendCount = 0;
        if (rdbtnlstLevel.SelectedValue != "")
            cinfo.CommentLevel = int.Parse(rdbtnlstLevel.SelectedValue.ToString());
        else
            cinfo.CommentLevel = 0;
        cinfo.CommentType = 0;
        cinfo.Content = txtContent.Text;

        cinfo.CreatedBy = int.Parse(ViewState["UserID"].ToString());
        cinfo.CreatedRealName = ViewState["RealName"].ToString();
        cinfo.CreatedUserName = ViewState["UserName"].ToString();
        cinfo.CreatedIP = PowerCreator.LMS.Common.Utils.IPUtils.GetIP;
        cinfo.CreatedTime = DateTime.Now;
        cinfo.DeleteState = 1;
        cinfo.FuCommentCount = 0;
        cinfo.IsDelete = 0;
        cinfo.IsEditor = 0;
        cinfo.IsFuComment = 0;
        cinfo.IsShow = 0;
        cinfo.IsState = 0;
        cinfo.OrderBy = 0;
        cinfo.StateCount = 0;

        cinfo.PlayTime = PowerCreator.LMS.Common.Utils.TimeUtils.GetTimeQian(ViewState["PlayTime"].ToString()).ToString();
        cinfo.ResourceID = int.Parse(ViewState["ResourceID"].ToString());
        cinfo.Title = txtTitle.Text;

        int vid = 0;
        string msg = string.Empty;
        if (commentManager.AddComment(cinfo,ref vid))
        {
            msg = "添加成功!";
        }
        else
        {
            msg = "添加数据出现异常!";
        }

        PowerCreator.LMS.Common.Script.Script.ShowAndCloseMe(Page, msg);
    }
}
